package com.dgshanger.sanhxiaofeisc.mvp.presenter

import android.text.TextUtils
import com.dgshanger.sanhxiaofeisc.mvp.contract.FeedbackContract
import com.dgshanger.sanhxiaofeisc.mvp.model.FeedbackModel
import com.dgshanger.sanhxiaofeisc.ui.person.feedback.FeedbackSuccessActivity
import com.xx.baseuilibrary.mvp.BaseRxMvpPresenter
import com.xx.baseutilslibrary.network.rx.RxHttpObserver

/**
 * FeedbackPresenter
 * 沉迷学习不能自拔
 *
 * Describe：意见反馈页面 @see )
 * Created by 雷小星🍀 on 2018/4/28 14:08.
 */

class FeedbackPresenter : BaseRxMvpPresenter<FeedbackContract.Model, FeedbackContract.View>(), FeedbackContract.Presenter {

    override fun referFeedback() {

        val content = getView()!!.content

        if (TextUtils.isEmpty(content)) {
            getView()?.showToast("请输入反馈内容哦")
            return
        }

        getModel().referFeedback(content, object : RxHttpObserver<Any>() {

            override fun onCompleted(msg: String?, entity: Any?) {
                getView()?.showToast(msg)
                getView()?.startActivity(FeedbackSuccessActivity::class.java)
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

            override fun onLoadingStart() {
                attachObserver(this)
                getView()?.showLoadingDialog()
            }

            override fun onLoadingFinish() {
                getView()?.dismissLoadingDialog()
            }
        })
    }

    override fun createModel(): FeedbackContract.Model = FeedbackModel()
}
